//
//  File.swift
//  WeiBo_One
//
//  Created by 李炎 on 15/10/27.
//  Copyright © 2015年 蜡笔小炎. All rights reserved.
//

import Foundation
import UIKit

class StatusViewModel: CustomDebugStringConvertible {
    
    /// 微博模型
    var status: Status
    /// 用户头像地址
    var userProfileUrl: NSURL {
        return NSURL(string: status.user?.profile_image_url ?? "")!
    }
    /// 用户默认头像
    var userDefaultImage: UIImage {
        return UIImage(named: "avatar_default_big")!
    }
    /// 用户认证图像 认证类型，-1：没有认证，0，认证用户，2,3,5: 企业认证，220: 达人
    var userVipImage: UIImage? {
        switch (status.user?.verified_type ?? -1) {
        case 0: return UIImage(named: "avatar_vip")
        case 2, 3, 5: return UIImage(named: "avatar_enterprise_vip")
        case 220: return UIImage(named: "avatar_grassroot")
        default: return nil
        }
    }
    /// 会员图标
    var userMemberImage: UIImage? {
        if status.user?.mbrank > 0 && status.user?.mbrank < 7 {
            return UIImage(named: "common_icon_membership_level\(status.user!.mbrank)")
        }
        return nil
    }
    //缩略图url数组
    var thumvnailUrls: [NSURL]?
    //返回行高
    var rowHeight: CGFloat {
        let cell = StatusCell(style: .Default, reuseIdentifier: HomeTableViewCellReuseId)
        
        return cell.rowHeight(self)
    }
    
    
    
    init(status: Status) {
        self.status = status
        //创建配图URL数组
        if status.pic_urls?.count >= 0 {
            thumvnailUrls = [NSURL]()
            for dict in status.pic_urls! {
                let url = NSURL(string: dict["thumbnail_pic"]!)
                
                thumvnailUrls?.append(url!)
            }
        }
    }
    
    var description: String {
        return status.description + "\n配图数组 \((thumvnailUrls ?? []) as NSArray)"
    }
    
    var debugDescription: String {
        return status.description
    }
}